import {WidgetClass} from "./widget";
export class WidgetSlider extends WidgetClass {
  constructor(options = {}) {
    super(options);
    const {ports, UI} = options
    if (UI) {
      this.UI.data = UI.data
    } else {
      this.UI.data = {
        layout: "vertical",
        trackColor: "#E5E5E5",
        valueColor: "#2D69E0",
        divisions: 10,
        minLimit: 0,
        maxLimit: 100,
      };
    }
    if (ports) {
      this.ports = ports;
    } else {
      this.ports = this.assembleDefaultPorts();
    }
  }

  assembleDefaultState(options = {}) {
    const superState = super.assembleDefaultState(options);
    return {
      ...superState,
      values: {
        value: 0,
      },
    };
  }

  assembleDefaultPorts() {
    const superState = super.assembleDefaultPorts();
    return {
      ...superState,
      values: [
       ...superState.values,
        {
          name: "进度",
          key: "value",
          type: "double",
          value: 0.0,
        },
        {
          name: "整数进度",
          key: "intValue",
          type: "int",
          value: 0,
        }
      ],
      events: [
        {
          name: "数值改变事件",
          key: `valueChange-${this.id}`,
          eventType: "valueChange",
          type: "event",
          action: [],
        },
      ],
    };
  }
}
